import os.path
import ddddocr
import requests
from lxml import etree

url = 'https://jiaoshi.ahedu.gov.cn/selfservice/queryadmin/getOriginalKey'


headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
}
# 对ddddocr进行实例化
ocr = ddddocr.DdddOcr()

# 验证码图片地址
yzm_url = 'https://jiaoshi.ahedu.gov.cn/selfservice/vcode'
# 发起网络请求
res = requests.get(yzm_url)
with open('yzm.jpg', 'wb') as f:
    f.write(res.content)

# 读取验证码图片
with open('yzm.jpg', 'rb')as f:
    # 读取图片信息
    img_bytes = f.read()
# 识别验证码
yanzheng = ocr.classification(img_bytes)
res = requests.post(url, headers=headers,data={'yhm': '342426199310212823',
'xm':'袁航',
'yx': '448556101@qq.com',
'yzm': yanzheng})
html = res.content.decode()
# print(html)
tree = etree.HTML(html)
print(html)
